import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

public class FileClass {
	
	File myFile = new File("readMe.txt");
	
	public void writeFile(String myString){
		BufferedWriter myWriter = null;
		
		try {
			myWriter = new BufferedWriter(new FileWriter(myFile));
		} catch (IOException e) {
			System.out.println("Unable to find the file: " + myFile.toString());
		}
		
		try {
			myWriter.write(myString);
		} catch (IOException e) {
			System.out.println("Unable to write to the file: " + myFile.toString());
		}
		
		try {
			myWriter.flush();
			myWriter.close();
		} catch (IOException e) {
			System.out.println("Unable to close the file: " + myFile.toString());
			e.printStackTrace();
		}
	}
	

	StringBuffer sb = null;
	
	public String readFile(){
		try {
			String myScanLine = new String();
			Scanner scanRead = new Scanner(myFile);
			sb = new StringBuffer();
			
			while (scanRead.hasNextLine()) {
				myScanLine = scanRead.nextLine();
				sb.append(myScanLine);
				sb.append("\n");
				}
			GUIclass.setTextFieldWithText(sb.toString());
			scanRead.close();
		} catch (FileNotFoundException e) {
			System.out.println("File Not Found: " + myFile.toString());
		}
		return null;
	}

	public String getSbString() {
		return sb.toString();
	}

}
